﻿@model dynamic

@{
    ViewBag.Title = "出区召回";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style>
    .dv-body {
        /*background-color: #00a0e9;*/
        width: 100%;
    }

    .dv-left {
        width: 120px;
        float: left;
    }

    .dv-left-title {
        width: 100%;
        height: 30px;
        line-height: 30px;
        background-color: #00a0e9;
        text-align: center;
        color: white;
    }

    .dv-right {
        float: left;
        margin-left: 5px;
    }
     .dv-body {
        overflow-y:hidden;
    }
       .gridPanel .ui-jqgrid-bdiv {
      overflow-x:hidden;
           }
       
</style>
<div class="dv-body" style="background-color: white;">
    <div class="dv-left">
        <div class="dv-left-title">病区列表</div>
        @*<table id="gridBqList"></table>*@
        @Html.Partial("_WardTreeForm")
    </div>
    <div class="dv-right">
        <form name="form1">
            <div class="panel panel-default">
                <div class="panel-heading navb-bg">
                    筛选条件
                </div>
                <div>
                    <table class="form">
                        <tr>
                            <th class="formTitle">姓名：</th>
                            <td class="formValue">
                                <input id="txt_name" class="form-control" placeholder="姓名" />
                            </td>
                            <th class="formTitle">开始日期：</th>
                            <td class="formValue">
                                <input id="txt_ksrq" class="form-control input-wdatepicker formClearIgnore" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', onpicked: function () { refleshPatientList(); } })" value="@DateTime.Now.ToString("yyyy-MM-01")" />
                            </td>
                            <th class="formTitle">结束日期：</th>
                            <td class="formValue">
                                <input id="txt_jsrq" class="form-control input-wdatepicker formClearIgnore" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', onpicked: function () { refleshPatientList(); } })" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                            </td>
                            <td class="formTitle">
                                <input type="button" id="btn_search" class="btn btn-md btn-primary" value="查询" />
                            </td>
                            <td colspan="1"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
        <div class="gridPanel">
            <table id="gridPatList"></table>
            <div id="gridPager"></div>
        </div>
    </div>
</div>
<script lang="javascript">
    $(document).ready(function () {

        DefaultCheck();
    });
    //默认选中根节点.
    function DefaultCheck() {
        var firstid = $("div[id^='wardTree_']:first").attr("id").replace("wardTree_", "");//根节点病区代码
        var addstyleid = 'wardTree_' + firstid;
        var item = new Object();
        item.id = firstid;
        $("#" + addstyleid + "").addClass('bbit-tree-selected');//增加选中样式
        wardTree_onnodeclick(item);
    }
    var bqdm = null;
        $(".dv-body").height($(window).height());
        $(".dv-body").width($(window).width());
        var rightWidth = $(".Newtouch_iframe", parent.document).width() - $(".dv-left").width() -5;
        $(".dv-right").width(rightWidth-20);
    function wardTree_onnodeclick(item) {

        bqdm = item.id;
        GetPatientList(bqdm);
        refleshPatientList();
    }
    //刷新事件
    function refleshPatientList() {
        $("#btn_search").trigger('click');
    }
    $("#btn_search").click(function () {
        var keyValue = bqdm;
        if (!!!keyValue) {
            $.modalAlert("请选中病区", 'warning');
            return;
        }
        if ($('#txt_ksrq').val() && $('#txt_jsrq').val() && ($('#txt_ksrq').val() > $('#txt_jsrq').val())) {
            $.modalAlert("开始日期不能大于结束时间", 'warning');
            return;
        }
        $("#gridPatList").jqGrid('setGridParam', {
            postData: { keyword: $('#txt_name').val(), ksrq: $('#txt_ksrq').val(), jsrq: $('#txt_jsrq').val(), bqdm: bqdm },
        }).trigger('reloadGrid'); //重新加载当前表格
    });
    // 查询条件
    function getSearchPostData() {
        var keyword = $('#txt_name').val();
        var ksrq = $('#txt_ksrq').val();
        var jsrq = $('#txt_jsrq').val();
       return{ keyword: keyword, ksrq: ksrq, jsrq: jsrq };
     
    }
    function GetPatientList(bqdm) {
        var $gridList = $("#gridPatList");
        var Querydata = getSearchPostData();
        Querydata["bqdm"] = bqdm;
        //alert(bqdm);
        $gridList.dataGrid({
                //获取出区待结算病人信息
            url: "/EntryRegistration/GetOutAreaPatlist",
            postData: Querydata,
            dataType: "json",
            height: $(window).height() - 155,
            width: $(".Newtouch_iframe", parent.document).width() - $(".dv-left").width() - 25,
            autowidth: false,//根据父容器宽度自适应调整
            shrinkToFit: true,
            //unwritten: false,
            //multiselect: true,
            colModel: [
               { label: 'Id', name: 'Id', hidden: true },
               { label: '住院号', name: 'zyh', align: 'center', width: 80 },
               { label: '姓名', name: 'xm', align: 'center', width: 100 },
               {
                   label: '性别', name: 'sex', align: 'center', width: 40, formatter: function (val) {
                       return $.getGender(val);
                   }
               },
               { label: '年龄', name: 'nl', align: 'center', width: 40 },
                { label: '床号', name: 'cwmc', align: 'center', width: 80 },
               //{ label: '入院日期', name: 'ryrq', align: 'center', width: 100, formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d' } },
               { label: '费用类型', name: 'brxzmc', align: 'center', width: 80 },
               { label: '入院诊断', name: 'zzdmc', align: 'center', width: 120 },

               { label: '出区日期', name: 'cqrq', align: 'center', width: 100, formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d' } },
               { label: '床位医生', name: 'ysxm', align: 'center', width: 100 }, {
                   label: "操作", name: "zyh", align: "center", width: 80,
                   formatter: function (cellvalue) {
                       return "<a href=\#\" onclick='recall(\"" + cellvalue + "\")'' title='出区召回' style='text-decoration: none;color: #dd4b39;cursor: pointer;'>召  回</a>";
                   }
               }
            ],
            pager: "#gridPager",
            sortname: 'zyh asc',
            viewrecords: true,
        });
    }

    //召回
    function recall(zyh) {
        if (zyh == null || zyh == "") {
            $.modalAlert("请选择一个患者", 'warning');
            return;
        }
        $.modalConfirm("确定要召回吗？", function (flag) {
            if (flag) {
                $.ajax({
                    type: "POST",
                    url: "/EntryRegistration/SaveRecallOutArea",
                    data: { zyh: zyh,bqdm:bqdm },
                    dataType: "json",
                    success: function (ajaxresp) {
                        if (ajaxresp.state == "success") {
                            $.modalMsg('召回成功', 'success');
                        }
                        else {
                            $.modalAlert(ajaxresp.message, 'warning');
                        }
                        refleshPatientList();
                    }
                });
            }
        });
    }
</script>